import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  Patch,
  ParseIntPipe,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { KnowledgePointService } from './knowledge-point.service';
import { CreateKnowledgePointDto } from './dto/create-knowledge-point.dto';
import { UpdateKnowledgePointDto } from './dto/update-knowledge-point.dto';
import { KnowledgePointQueryDto } from './dto/knowledge-point-query.dto';

@ApiTags('知识点管理')
@Controller('knowledge-points')
export class KnowledgePointController {
  constructor(private readonly knowledgePointService: KnowledgePointService) {}

  @Post()
  @ApiOperation({ summary: '创建知识点' })
  async create(@Body() createDto: CreateKnowledgePointDto) {
    return this.knowledgePointService.create(createDto);
  }

  @Put(':id')
  @ApiOperation({ summary: '更新知识点' })
  async update(
    @Param('id') id: string,
    @Body() updateDto: UpdateKnowledgePointDto,
  ) {
    return this.knowledgePointService.update(BigInt(id), updateDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除知识点' })
  async delete(@Param('id') id: string) {
    return this.knowledgePointService.delete(BigInt(id));
  }

  @Post('batch-delete')
  @ApiOperation({ summary: '批量删除知识点' })
  async batchDelete(@Body('ids') ids: string[]) {
    return this.knowledgePointService.batchDelete(ids.map((id) => BigInt(id)));
  }

  @Get()
  @ApiOperation({ summary: '获取知识点列表' })
  async findAll(@Query() query: KnowledgePointQueryDto) {
    return this.knowledgePointService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '获取知识点详情' })
  async findOne(@Param('id') id: string) {
    return this.knowledgePointService.findOne(BigInt(id));
  }
}
